using System;
using System.IO;
using GGEditor.API.Documents;
using GGEditor.API.Editors;

namespace GGEditor.API.Samples.LandAndWater
{
	public class Exporter : IFileExporter
	{
		#region Implementation of IFileExporter

		public void Export(IEditorModel eModel, string filePath)
		{
			Model model = eModel as Model;
			if (model == null)
				throw new InvalidOperationException();

			using (FileStream fileStream = new FileStream(filePath, FileMode.Create))
			using (BinaryWriter r = new BinaryWriter(fileStream))
			{
				r.Write(model.Width);
				r.Write(model.Height);
				for (int y = 0; y < model.Height; y++)
				{
					for (int x = 0; x < model.Width; x++)
					{
						r.Write(model[x, y]);
					}
				}
			}
		}

		#endregion
	}
}